import React from "react";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { RouteRawState } from "../types";
import { routes } from "./routes";

const routerView = (routes: RouteRawState[]) => {
  return routes.map((v, i) => {
    return <Route path={v.path} element={v.element} key={i}>
			{/* 递归渲染 */}
			{ v.children && routerView(v.children) }
		</Route>;
  });
};

const Index: React.FC = () => {
  return (
    <BrowserRouter>
      <React.Suspense>
        <Routes>{routerView(routes)}</Routes>
      </React.Suspense>
    </BrowserRouter>
  );
};

export default Index
